import request from '@/utils/request'

export function getSafeArray (params) {
  var data = fromData(params)
  return request({
    url: '/safe/getSafeArray',
    method: 'post',
    data
  })
}

export function getSafeInfo (params) {
  var data = fromData(params)
  return request({
    url: '/safe/getSafeInfo',
    method: 'post',
    data
  })
}

export function addSafeData (params) {
  var data = fromData(params)
  return request({
    url: '/safe/addSafe',
    method: 'post',
    data
  })
}

export function editSafeData (params) {
  var data = fromData(params)
  return request({
    url: '/safe/editSafe',
    method: 'post',
    data
  })
}

export function delSafeData (params) {
  var data = fromData(params)
  return request({
    url: '/safe/del_safe',
    method: 'post',
    data
  })
}

function fromData (params) {
  let formData = new FormData()
  for (const it in params) {
    if (!Object.is(params[it], null) && !Object.is(params[it], '')) {
      formData.append(it, params[it])
    }
  }
  return formData
}
